import { FirstParma } from "@Tea/model"
import { ElLoading } from "element-plus"
import { ref } from "vue"

type LoadingServiceReturn = ReturnType<typeof ElLoading.service>
type LoadingServiceParam = FirstParma<typeof ElLoading.service>

/**
 * @vuese 全局的loading
 * @returns 
 */
export function useGloablLoading() {
  const loading = ref<null | LoadingServiceReturn>(null)

  const showLoading = (options?: LoadingServiceParam) => { 
    loading.value = ElLoading.service(options) as any
  }

  const closeLoading = () => {
    loading.value ? loading.value.close() :  ElLoading.service().close()
  }

  return { showLoading, closeLoading }
}